import { store } from '../stores'
import { Redirect, useLocation } from 'react-router-dom'
const AuthRoute = ({ children }: { children: JSX.Element }) => {
  const location = useLocation()
  const token = store.getState().userInfo
  // console.log(location)

  if (token) {
    return children
  } else {
    return <Redirect to={`/login?redirect=${location.pathname}`} />
  }
}

export default AuthRoute
